@extends('layouts.application')

@section('content')
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">品牌管理</strong> /
                    <small>Brands Manage</small>
                </div>
            </div>

            <hr>
            @include('layouts._flash')

            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a href="{{route('brands.create')}}" class="am-btn am-btn-default"><span class="am-icon-plus"></span>
                                新增
                            </a>
                        </div>
                    </div>
                </div>

                <div class="am-u-sm-12 am-u-md-3">

                    <form method="get">

                        <div class="am-input-group am-input-group-sm">

                            <input type="text" class="am-form-field" name="keyword" value="{{Request::input('keyword')}}">
                            <span class="am-input-group-btn">
                                <button class="am-btn am-btn-default" type="submit">搜索</button>
                            </span>
                        </div>
                    </form>

                </div>
            </div>

            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-id">编号</th>
                                <th>缩略图</th>
                                <th class="table-title">品牌名称</th>
                                <th class="table-type">品牌描述</th>
                                <th class="table-author am-hide-sm-only">是否显示</th>
                                <th class="table-date am-hide-sm-only">排序</th>
                                <th class="table-set">操作</th>
                            </tr>
                            </thead>
                            <tbody>

                            @foreach ($brands as $b)
                                <tr data-id="{{$b->id}}">
                                    <td >{{$b->id}}</td>
                                    <td><img src="{{$b->thumb}}" alt="" style="max-height: 60px;"></td>
                                    <td>{{$b->name}}</td>
                                    <td class="am-hide-sm-only">{{$b->desc}}</td>
                                    <td class="am-hide-sm-only">
                                           {!! is_something('is_show',$b) !!}
                                    </td>
                                    <td><input type="text" name="sort_order" class="am-input-sm sort_order" value="{{$b->sort_order}}"></td>
                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">

                                                <button class="am-btn am-btn-default am-btn-xs am-text-secondary">
                                                    <span class="am-icon-pencil-square-o"></span>
                                                    <a href="{{route('brands.edit',$b->id)}}">  编辑</a>
                                                </button>

                                                    <a class="am-btn am-btn-default am-btn-xs am-hide-sm-only"
                                                            href="{{route('brands.copy', $b->id)}}" data-method="get" data-token="{{csrf_token()}}" data-confirm="确认复制吗?" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only">
                                                        <span class="am-icon-copy"></span>复制
                                                    </a>
                                                <a href="{{route('brands.destroy',$b->id)}}" data-method="delete" data-token="{{csrf_token()}}" data-confirm="确认删除吗?"
                                                   class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only">
                                                    <span class="am-icon-trash-o"></span> 删除
                                                </a>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                        <div class="am-cf">
                            共 {{ $brands->total() }} 条记录
                            <div class="am-fr">
                                {{ $brands->appends(Request::all())->links() }}
                            </div>
                        </div>
                        <hr/>
                        <p>注：.....</p>
                    </form>
                </div>

            </div>
        </div>

        <footer class="admin-content-footer">
            <hr>
            <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
        </footer>

    </div>
@endsection
@section('js')
    <script>
        $(function(){
         $(".sort_order").change(function(){
           var info={
               id:$(this).parents("tr").data('id'),
               sort_order:$(this).val()
           };
             console.log($(this).val());
           $.ajax({
               type:"PATCH",
               url:"/lxSystem/brands/sort_order",
               data:info
           });
       })
            $('.is_something').click(function(){
                var _this=$(this);
                var info={
                    id:_this.parents("tr").data('id'),
                    attr:_this.data('attr')
                };
                $.ajax({
                    type:"PATCH",
                    url:"/lxSystem/brands/is_something",
                    data:info,
                    success:function(){
                        _this.toggleClass('am-icon-check am-icon-close');
                    }
                });

            })
     })
    </script>
@endsection

